package com.crl.rcdp.sys.dao;

import com.crl.dao.BaseDao;
import com.crl.rcdp.sys.model.SysUserRole;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/6/22 11:10
 */
@Repository
public class SysUserRoleDao2 extends BaseDao<SysUserRole, SysUserRole> {

    /**
     * 新增用户角色对应
     *
     * @param sysUserRole
     * @return
     */
    public int add(SysUserRole sysUserRole) {
        String sql = "insert into td_sys_user_role(user_id,role_id) values(:userId,:roleId)";
        return insert(sql, sysUserRole);
    }

    /**
     * 按照userId删除所有的用户对应角色
     *
     * @param userId
     * @return
     */
    public int deleteByUserId(int userId) {
        String sql = "delete from td_sys_user_role where user_id=?";
        return delete(sql, userId);
    }


    /**
     * 根据userId获取所有用户对应角色
     *
     * @param userId
     * @return
     */
    public List<SysUserRole> listByUserId(int userId) {
        String sql = "select user_id,role_id from td_sys_user_role where user_id=?";
        return list(sql, userId);
    }
}
